# -*- coding: utf-8 -*-

from abc import ABC, abstractmethod

from src.utils.BaseLogger import BaseLogger


class AbstractHandler(ABC, BaseLogger):

    def __init__(self, subparsers, config):
        super().__init__()
        self.subparsers = subparsers
        self.config = config
        self._setup_arg(subparsers)

    def _check(self, args):
        """检查处理条件的方法"""
        return True

    @abstractmethod
    def _process(self, args):
        """处理请求的具体逻辑"""
        pass

    @abstractmethod
    def _setup_arg(self, subparsers):
        """构建命令行参数"""
        pass

    def check_fail(self, args):
        pass

    def do_process(self, args):
        self.logger.info("Start processing...")
        if self._check(args):
            self._process(args)
        else:
            self.check_fail(args)
